<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

if(isset($_SESSION['u_nic'])&&isset($_GET['id'])) {
	include('php/lib/panel_inc.php');
	if(($_POST['dns1'] != "") AND ($_POST['dns2'] != "")) {
		$dns1 = preg_replace('#([^a-z0-9\-\_.])+#i', '', strtolower($_POST['dns1']));
		$dns2 = preg_replace('#([^a-z0-9\-\_.])+#i', '', strtolower($_POST['dns2']));
		$dns3 = preg_replace('#([^a-z0-9\-\_.])+#i', '', strtolower($_POST['dns3']));
		$dns4 = preg_replace('#([^a-z0-9\-\_.])+#i', '', strtolower($_POST['dns4']));
		$infos_dom = mysql_fetch_array(query("SELECT 
								comptes_domain.*,
								users.reg_contact_id,
								users.u_nic
								FROM comptes_domain
								LEFT JOIN users
								ON comptes_domain.u_nic = users.u_nic
								WHERE comptes_domain.id='".intval($_GET['id'])."' AND comptes_domain.u_nic='".$_SESSION['u_nic']."'"));
		// Mise en array
		
		$update['dns1'] = $dns1;
		$update['dns2'] = $dns2;
		$update['dns3'] = $dns3;
		$update['dns4'] = $dns4;
		$update['reg_contact_id'] = $infos_dom['reg_contact_id'];
		if($infos_dom['lock'] == 1) {
			$update['registry_status'] = 64;
		}
		else {
			$update['registry_status'] = 0;
		}
		include ROOT.'php/lib/registrars/'.$registrar[$infos_dom['id_registrar']].'.inc.php';
		$_domgest = new bh_doms_gest();
		$tid = $_domgest->dom_update($infos_dom['domaine'],$update);
		query("UPDATE comptes_domain SET dns1 = '$dns1', dns2 = '$dns2', dns3 = '$dns3', dns4 = '$dns4', etat = '7', tid = '$tid' WHERE id = '".intval($_GET['id'])."' AND u_nic = '".$_SESSION['u_nic']."'");
		header("Location: domaine.html?id=".intval($_GET['id']));
	}
	else {
		$title = "Modification des serveurs DNS";
		$tplinc = "panel-domaine-serverdns";
		$tpl->assign(array(
			'iconesleft' => 3,
			'prod' => '1',
			'prod_id' => intval($_GET['id'])
		));
		$dom_current = intval($_GET['id']);
		$infos_dom = mysql_query("SELECT domaine,dns1,dns2,dns3,dns4,zone_dns,etat FROM comptes_domain WHERE id='".$dom_current."' AND u_nic='".$_SESSION['u_nic']."'");
		if(mysql_num_rows($infos_dom) == 1) {
			$infos_dom = mysql_fetch_array($infos_dom);
			if($infos_dom['etat'] == "1") {
				if($infos_dom['zone_dns'] == 0) {
					if($infos_dom['etat'] == 7) {
						$modif = "1";
					}
					else {
						$modif = "0";
					}
					$tpl->assign(array(
						"current_dom" => $infos_dom['domaine'],
						"action" => intval($_GET['action']),
						"modif" => $modif,
						"dns1" => $infos_dom['dns1'],
						"dns2" => $infos_dom['dns2'],
						"dns3" => $infos_dom['dns3'],
						"dns4" => $infos_dom['dns4'],
						));
						$parse = 1;
				}
			}
			else { header("Location:/panel/domaine.html?id=".intval($_GET['id'])); }
		}
	}
}
else { header("Location:/site/connexion.html"); }

?>